package com.mcflies.aotoPartsManager.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import net.sf.json.JSONObject;

import org.apache.struts2.StrutsStatics;

import com.mcflies.aotoPartsManager.util.AutoPartsConstantKey;
import com.mcflies.aotoPartsManager.util.AutoPartsGUIDef;
import com.mcflies.commons.commons.CommonFunction;
import com.mcflies.commons.commons.CommonsConstantKey;
import com.opensymphony.xwork2.ActionContext;

/**
 * 
 * AutoPartDSAction.java
 * 
 * @describe：响应汽车配件管理系统下拉数据源请求
 * @Copyright(c) 2012-2024 Study,mcfly
 * @author mcfly_jun
 */
public class AutoPartDSAction {
//	private Logger log = Logger.getLogger(AutoPartDSAction.class);
	ServletContext servletContext = (ServletContext) ActionContext.getContext().get(StrutsStatics.SERVLET_CONTEXT);
	private JSONObject resultObj = new JSONObject();
	private String provinceName;

	/**
	 * @describe:响应"所属地域"下拉数据源请求
	 * @return
	 */
	public String getAreaDS() {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Object> rows = new ArrayList<Object>();
		for (int i = 0; i < 10; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("areaId", String.valueOf(i));
			map.put("areaName", "地域~~" + i);
			rows.add(map);
		}
		retMap.put(AutoPartsGUIDef.CommonGuiDef.root, rows);
		resultObj = JSONObject.fromObject(retMap);
		return AutoPartsConstantKey.RETURN_JSON_DATA_STORE;
	}

	/**
	 * @describe:响应"所属地域"下拉数据源请求
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getBankDS() {
		Map<String, Object> retMap = (Map<String, Object>) servletContext
				.getAttribute(CommonsConstantKey.BaseDataLoadListenerConstant.BaseDataLoadListenerBank);
		if (null == retMap) {
			retMap = CommonFunction.getAllBankInfo();
			servletContext.setAttribute(CommonsConstantKey.BaseDataLoadListenerConstant.BaseDataLoadListenerBank,
					retMap);
		}
		resultObj = JSONObject.fromObject(retMap);
		return AutoPartsConstantKey.RETURN_JSON_DATA_STORE;
	}

	/**
	 * @describe:响应"所属省份"下拉数据源请求
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getProvince() {
		Map<String, Object> retMap = (Map<String, Object>) servletContext
				.getAttribute(CommonsConstantKey.BaseDataLoadListenerConstant.BaseDataLoadListenerProvince);
		resultObj = JSONObject.fromObject(retMap);
		return AutoPartsConstantKey.RETURN_JSON_DATA_STORE;
	}

	/**
	 * @describe:响应"所属地市"下拉数据源请求
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getRegion() {
		Map<String, Object> provinceRegionMap = (Map<String, Object>) servletContext
				.getAttribute(CommonsConstantKey.BaseDataLoadListenerConstant.BaseDataLoadListenerProvinceRegionMap);
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Object> regionList = new ArrayList<Object>();
		if (null != provinceName && null != provinceRegionMap) {
			regionList = (List<Object>) provinceRegionMap.get(provinceName);
		}
		retMap.put(AutoPartsGUIDef.CommonGuiDef.root, regionList);
		resultObj = JSONObject.fromObject(retMap);
		return AutoPartsConstantKey.RETURN_JSON_DATA_STORE;
	}

	public JSONObject getResultObj() {
		return resultObj;
	}

	public void setResultObj(JSONObject resultObj) {
		this.resultObj = resultObj;
	}

	public String getProvinceName() {
		return provinceName;
	}

	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}
}
